package com.ycsj.goldmedalnewconcept.fragment;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.json.JSONException;
import org.json.JSONObject;

import com.google.gson.Gson;
import com.squareup.okhttp.Call;
import com.squareup.okhttp.Callback;
import com.squareup.okhttp.FormEncodingBuilder;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response;
import com.squareup.picasso.Picasso;
import com.ycsj.goldmedalnewconcept.MainActivity;
import com.ycsj.goldmedalnewconcept.activity.GonggaoActivity;
import com.ycsj.goldmedalnewconcept.activity.HuodongActivity;
import com.ycsj.goldmedalnewconcept.activity.MyQuanziActivity;
import com.ycsj.goldmedalnewconcept.adapter.EvaluationAdapter;
import com.ycsj.goldmedalnewconcept.adapter.MyPagerAdapter;
import com.ycsj.goldmedalnewconcept.bean.LocResponse;
import com.ycsj.goldmedalnewconcept.bean.QuanzishouyeResponse;
import com.ycsj.goldmedalnewconcept.constant.Constant;
import com.ycsj.goldmedalnewconcept.utils.SPUtil;
import com.ycsj.goldmedalnewconcept.R;

import android.Manifest;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.SystemClock;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

//圈子
public class FriendsFragment extends Fragment implements OnClickListener {

	private Activity ctx;
	private View layout;
	private MainActivity parentActivity;
	private ViewPager mViewPager;
	private List<ImageView> mImageViewList;
	private int[] images = { R.drawable.b1, R.drawable.b2, R.drawable.b3,
			R.drawable.b4 };
	private int currentPosition = 1;
	private int dotPosition = 0;
	private int prePosition = 0;
	private LinearLayout mLinearLayoutDot;
	private List<ImageView> mImageViewDotList;
	private EvaluationAdapter mAdapter;
	private LinearLayout tv_gonggao;
	private LinearLayout tv_huodong;
	private LinearLayout tv_quanzi;
	private Intent intent;
	private TextView tv_gonggaotitle;
	private TextView tv_huodongtitle;
	private TextView tv_quanzititle;
	private ImageView iv_gonggaoimg;
	private ImageView iv_huodongimg;
	private ImageView iv_quanziimg;
	
	private ImageView iv_newgonggao;
	private ImageView iv_newhuodong;
	private ImageView iv_newquanzi;

	private String account;
	private String role;
	private String NoticeInfo_ID = "";
	private String MeetingInfo_ID = "";
	private String CircleMessage_ID = "";
	
	private String TNoticeInfo_ID = "";
	private String TMeetingInfo_ID = "";
	private String TCircleMessage_ID = "";
	
	
	

	private String url;
	private String provider;// 位置提供器
	private LocationManager locationManager;// 位置服务
	private Location location;
	private String province = "";
	private String city = "";
	private String district = "";
	private int i = 0;
	Handler handler = new Handler() {
		@Override
		public void handleMessage(Message msg) {
			super.handleMessage(msg);
			if (msg.what == 1) {
				mViewPager.setCurrentItem(currentPosition, false);
			}
		}
	};

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		if (layout == null) {
			ctx = this.getActivity();
			parentActivity = (MainActivity) getActivity();
			layout = ctx.getLayoutInflater().inflate(R.layout.fragment_friends,
					null);

			account = SPUtil.getString(getActivity(), "account", "");
			role = SPUtil.getString(getActivity(), "role", "");
			province = SPUtil.getString(getActivity(), "province", "");
			city = SPUtil.getString(getActivity(), "city", "");
			district = SPUtil.getString(getActivity(), "district", "");
			NoticeInfo_ID = SPUtil.getString(getActivity(), "NoticeInfo_ID", "");
			MeetingInfo_ID = SPUtil.getString(getActivity(), "MeetingInfo_ID", "");
			CircleMessage_ID = SPUtil.getString(getActivity(), "CircleMessage_ID", "");
			TNoticeInfo_ID = SPUtil.getString(getActivity(), "NoticeInfo_ID", "");
			TMeetingInfo_ID = SPUtil.getString(getActivity(), "MeetingInfo_ID", "");
			TCircleMessage_ID = SPUtil.getString(getActivity(), "CircleMessage_ID", "");

			
			
			initLocation();
			initView();
//			init();
			initData();

		} else {
			ViewGroup parent = (ViewGroup) layout.getParent();
			if (parent != null) {
				parent.removeView(layout);
			}
		}
		return layout;
	}
	
	
	@Override
	public void onResume() {
		// TODO Auto-generated method stub
		i++;
		init();
		super.onResume();
	}

	private void initLocation() {
		// locationManager = getSystemService(Context.LOCATION_SERVICE);//获得位置服务
		locationManager = (LocationManager) getActivity().getSystemService(
				"location");
		provider = judgeProvider(locationManager);

		if (provider != null) {// 有位置提供器的情况
			// 为了压制getLastKnownLocation方法的警告
			// if (getActivity().checkCallingUriPermission(getActivity(),
			// Manifest.permission.ACCESS_COARSE_LOCATION) !=
			// PackageManager.PERMISSION_GRANTED) {
			// return;
			// }
			// if (getActivity().checkCallingUriPermission(getActivity(),
			// Manifest.permission.ACCESS_FINE_LOCATION) !=
			// PackageManager.PERMISSION_GRANTED &&
			// getActivity().checkCallingOrSelfUriPermission(getActivity(),
			// Manifest.permission.ACCESS_COARSE_LOCATION) !=
			// PackageManager.PERMISSION_GRANTED) {
			// return;
			// }

			Criteria criteria = new Criteria();
			criteria.setAccuracy(Criteria.ACCURACY_COARSE);// 低精度，如果设置为高精度，依然获取不了location。
			criteria.setAltitudeRequired(false);// 不要求海拔
			criteria.setBearingRequired(false);// 不要求方位
			criteria.setCostAllowed(true);// 允许有花费
			criteria.setPowerRequirement(Criteria.POWER_LOW);// 低功耗

			// 从可用的位置提供器中，匹配以上标准的最佳提供器
			provider = locationManager.getBestProvider(criteria, true);
			// if (ActivityCompat.checkSelfPermission(getActivity(),
			// Manifest.permission.ACCESS_FINE_LOCATION) !=
			// PackageManager.PERMISSION_GRANTED &&
			// ActivityCompat.checkSelfPermission(getActivity(),
			// Manifest.permission.ACCESS_COARSE_LOCATION) !=
			// PackageManager.PERMISSION_GRANTED) {
			// // Log.d(TAG, "onCreate: 没有权限 ");
			// return;
			// }
			locationManager.requestLocationUpdates(provider, 0, 0,
					locationListener);
			location = locationManager.getLastKnownLocation(provider);

			if (location != null) {
				getLocation(location);// 得到当前经纬度并开启线程去反向地理编码
			} else {

				// getLocation(locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER));
				Log.e("testloc", "暂时无法获得当前位置");
			}
		} else {// 不存在位置提供器的情况

		}

	}

	/**
	 * LocationListern监听器 参数：地理位置提供器、监听位置变化的时间间隔、位置变化的距离间隔、LocationListener监听器
	 */

	LocationListener locationListener = new LocationListener() {

		@Override
		public void onStatusChanged(String provider, int status, Bundle arg2) {

		}

		@Override
		public void onProviderEnabled(String provider) {
			Log.d("testloc", "onProviderEnabled: " + provider + ".."
					+ Thread.currentThread().getName());
		}

		@Override
		public void onProviderDisabled(String provider) {
			Log.d("testloc", "onProviderDisabled: " + provider + ".."
					+ Thread.currentThread().getName());
		}

		@Override
		public void onLocationChanged(Location location) {
			Log.d("testlic", "onLocationChanged: " + ".."
					+ Thread.currentThread().getName());
			// 如果位置发生变化,重新显示
		}
	};

	private void initBaidu() {

		// TODO Auto-generated method stub
		OkHttpClient mOkHttpClient1 = new OkHttpClient();
		// 创建一个Request
		final Request request1 = new Request.Builder().url(url).build();
		Call call = mOkHttpClient1.newCall(request1);
		call.enqueue(callBack);

	}

	Callback callBack = new Callback() {

		@Override
		public void onFailure(Request arg0, IOException arg1) {
			// TODO Auto-generated method stub
		}

		@Override
		public void onResponse(Response arg0) throws IOException {
			
			try {
			String json = arg0.body().string();
			Log.e("testloc", json);
			json = json.replace("renderReverse&&renderReverse", "");
			json = json.replace("(", "");
			json = json.replace(")", "");
			Gson gson = new Gson();

			LocResponse fromJson = gson.fromJson(json, LocResponse.class);

			if (fromJson != null) {
				if (fromJson.result != null) {
					province = fromJson.result.addressComponent.province;
					city = fromJson.result.addressComponent.city;
					district = fromJson.result.addressComponent.district;

					SPUtil.putString(getActivity(), "province", province);
					SPUtil.putString(getActivity(), "city", city);
					SPUtil.putString(getActivity(), "district", district);
				}
			}
			
			} catch (Exception e) {
				// TODO: handle exception
				Log.e("error", e.toString());
			}
			
		}
	};

	/**
	 * 判断是否有可用的内容提供器
	 * 
	 * @return 不存在返回null
	 */
	private String judgeProvider(LocationManager locationManager) {
		List<String> prodiverlist = locationManager.getProviders(true);
		if (prodiverlist.contains(LocationManager.NETWORK_PROVIDER)) {
			return LocationManager.NETWORK_PROVIDER;
		} else if (prodiverlist.contains(LocationManager.GPS_PROVIDER)) {
			return LocationManager.GPS_PROVIDER;
		} else {
			// Toast.makeText(this,"没有可用的位置提供器",Toast.LENGTH_SHORT).show();
			Log.e("testloc", "没有可用的位置提供器");
		}
		return LocationManager.NETWORK_PROVIDER;
	}

	/**
	 * 得到当前经纬度并开启线程去反向地理编码
	 */
	public void getLocation(Location location) {
		String latitude = location.getLatitude() + "";
		String longitude = location.getLongitude() + "";
		url = "http://api.map.baidu.com/geocoder/v2/?ak=kkQ4Gq3e5Hdg2mdmFTNtZCzceWGtP06m&callback=renderReverse&location="
				+ latitude + "," + longitude + "&output=json&pois=0";
		initBaidu();
	}

	private void init() {

		OkHttpClient mOkHttpClient = new OkHttpClient();
		// mOkHttpClient.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
		FormEncodingBuilder builder = new FormEncodingBuilder();
		builder.add("type", "101");
		builder.add("c", account);
		builder.add("role", role);
		builder.add("province", province);
		builder.add("city", city);
		builder.add("area", district);
		builder.add("NoticeInfo_ID", NoticeInfo_ID);
		builder.add("MeetingInfo_ID", MeetingInfo_ID);
		builder.add("CircleMessage_ID", CircleMessage_ID);

		Log.e("province", province + "1");
		Log.e("city", city + "2");
		Log.e("district", district + "3");
		Request request = new Request.Builder()
				.url(Constant.SERVER_URL+"ManageMsg")
//				.url("http://pm.moregolden.com/ycsj_platform/ManageMsg")
				.post(builder.build())
				// .url(Constant.SERVER_URL + "ManageMsg").post(builder.build())
				.build();
		mOkHttpClient.newCall(request).enqueue(new Callback() {

			// http://192.168.0.198:8888/ycsj_platform/ManageMsg?type=101&c=13006314760&role=2&province=湖北省&city=武汉市&city=江汉区&NoticeInfo_ID=0&MeetingInfo_ID=0&CircleMessage_ID=0
			// http://pm.moregolden.com/ycsj_platform/ManageMsg?type=101&c=15333838051&role=2&province=%E6%B9%96%E5%8C%97%E7%9C%81&city=%E6%AD%A6%E6%B1%89%E5%B8%82&city=%E6%B1%9F%E6%B1%89%E5%8C%BA&NoticeInfo_ID=&MeetingInfo_ID=&CircleMessage_ID=
			@Override
			public void onFailure(Request arg0, IOException arg1) {

				try {
					getActivity().runOnUiThread(new Runnable() {
						@Override
						public void run() {
							Toast.makeText(getActivity(), "网络无响应，请检查网络连接", 0)
									.show();
							setDot();
							setViewPager();
							autoPlay();
						}
					});
				} catch (Exception e) {
					// TODO: handle exception
				}

			}

			@Override
			public void onResponse(Response arg0) throws IOException {
				// 解析Json数据，保存登录状态及身份信息

				Gson gson = new Gson();

				String json = arg0.body().string();
				Log.e("test", json);
				final QuanzishouyeResponse fromJson = gson.fromJson(json,
						QuanzishouyeResponse.class);
				try {
					getActivity().runOnUiThread(new Runnable() {
						@Override
						public void run() {
							// Toast.makeText(getActivity(), "数据收到", 0)
							// .show();
							if (fromJson != null) {

								iv_newgonggao.setVisibility(iv_newgonggao.GONE);
								iv_newhuodong.setVisibility(iv_newhuodong.GONE);
								iv_newquanzi.setVisibility(iv_newquanzi.GONE);

								if ("1".equals(fromJson.NoticeInfo_state)
										&& "1".equals(fromJson.NoticeInfo_isNew)) {

									iv_newgonggao
											.setVisibility(iv_newgonggao.VISIBLE);

									tv_gonggaotitle
											.setText(fromJson.NoticeInfo_Content);
									if (fromJson.NoticeInfo != null
											&& fromJson.NoticeInfo.size() != 0) {
										Picasso.with(getActivity())
												.load(fromJson.NoticeInfo
														.get(0))
												.into(iv_gonggaoimg);
									}

									TNoticeInfo_ID = fromJson.NoticeInfo_ID + "";
								}
								if ("1".equals(fromJson.MeetingInfo_state)
										&& "1".equals(fromJson.MeetingInfo_isNew)) {

									iv_newhuodong
											.setVisibility(iv_newhuodong.VISIBLE);

									tv_huodongtitle
											.setText(fromJson.MeetingInfo_Content);
									if (fromJson.MeetingInfo != null
											&& fromJson.MeetingInfo.size() != 0) {
										Picasso.with(getActivity())
												.load(fromJson.MeetingInfo
														.get(0))
												.into(iv_huodongimg);
									}

									TMeetingInfo_ID = fromJson.MeetingInfo_ID
											+ "";
								}
								if ("1".equals(fromJson.CircleMessage_state)
										&& "1".equals(fromJson.CircleMessage_isNew)) {

									iv_newquanzi
											.setVisibility(iv_newquanzi.VISIBLE);

									tv_quanzititle
											.setText(fromJson.CircleMessage_Content);
									if (fromJson.CircleMessage != null
											&& fromJson.CircleMessage.size() != 0) {
										Picasso.with(getActivity())
												.load(fromJson.CircleMessage
														.get(0))
												.into(iv_quanziimg);
									}

									TCircleMessage_ID = fromJson.CircleMessage_ID
											+ "";
								}
								
								if(i==1){
								if ("1".equals(fromJson.RollPicture_state)) {
									mImageViewList = new ArrayList<ImageView>();
									mImageViewDotList = new ArrayList<ImageView>();
									ImageView imageView = null;

									for (int i = 0; i < fromJson.RollPicture
											.size() + 2; i++) {
										if (i == 0) { // 判断当i=0为该处的ImageView设置最后一张图片作为背景
											ImageView imageView1 = new ImageView(
													getActivity());
											imageView1
													.setScaleType(ImageView.ScaleType.FIT_XY);
											Picasso.with(getActivity())
													.load(fromJson.RollPicture
															.get(fromJson.RollPicture
																	.size() - 1))
													.into(imageView1);
											// imageView.setBackgroundResource();

											mImageViewList.add(imageView1);
										} else if (i == fromJson.RollPicture
												.size() + 1) { // 判断当i=images.length+1时为该处的ImageView设置第一张图片作为背景
											ImageView imageView2 = new ImageView(
													getActivity());
											imageView2
													.setScaleType(ImageView.ScaleType.FIT_XY);
											Picasso.with(getActivity())
													.load(fromJson.RollPicture
															.get(0))
													.into(imageView2);

											// imageView.setBackgroundResource();
											mImageViewList.add(imageView2);
										} else {
											// 其他情况则为ImageView设置images[i-1]的图片作为背景
											ImageView imageView3 = new ImageView(
													getActivity());
											imageView3
													.setScaleType(ImageView.ScaleType.FIT_XY);
											Picasso.with(getActivity())
													.load(fromJson.RollPicture
															.get(i - 1))
													.into(imageView3);

											// imageView.setBackgroundResource(images[i
											// - 1]);
											mImageViewList.add(imageView3);
										}
									}
									setDotmod();
									setViewPagermod();
									autoPlay();
								} else {
									initData();
									setDot();
									setViewPager();
									autoPlay();
								}
								}
							}
						}
					});
				} catch (Exception e) {
					// TODO: handle exception
				}
			}
		});
	}

	// 设置自动播放
	private void autoPlay() {
		new Thread() {
			@Override
			public void run() {
				super.run();
				while (true) {
					SystemClock.sleep(3000);
					currentPosition++;
					handler.sendEmptyMessage(1);
				}
			}
		}.start();
	}

	private void setViewPager() {
		
		MyPagerAdapter adapter = new MyPagerAdapter(mImageViewList);

		mViewPager.setAdapter(adapter);

		mViewPager.setCurrentItem(currentPosition);
		// 页面改变监听
		mViewPager
				.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
					@Override
					public void onPageScrolled(int position,
							float positionOffset, int positionOffsetPixels) {

					}

					@Override
					public void onPageSelected(int position) {
						if (position == 0) { // 判断当切换到第0个页面时把currentPosition设置为images.length,即倒数第二个位置，小圆点位置为length-1
							currentPosition = images.length;
							dotPosition = images.length - 1;
						} else if (position == images.length + 1) { // 当切换到最后一个页面时currentPosition设置为第一个位置，小圆点位置为0
							currentPosition = 1;
							dotPosition = 0;
						} else {
							currentPosition = position;
							dotPosition = position - 1;
						}
						// 把之前的小圆点设置背景为暗红，当前小圆点设置为红色
						mImageViewDotList
								.get(prePosition)
								.setBackgroundResource(R.drawable.red_dot_night);
						mImageViewDotList.get(dotPosition)
								.setBackgroundResource(R.drawable.red_dot);
						prePosition = dotPosition;
					}

					@Override
					public void onPageScrollStateChanged(int state) {
						// 当state为SCROLL_STATE_IDLE即没有滑动的状态时切换页面
						if (state == ViewPager.SCROLL_STATE_IDLE) {
							mViewPager.setCurrentItem(currentPosition, false);
						}
					}
				});
	}
	
	
private void setViewPagermod() {
		
		MyPagerAdapter adapter = new MyPagerAdapter(mImageViewList);

		mViewPager.setAdapter(adapter);

		mViewPager.setCurrentItem(currentPosition);
		// 页面改变监听
		mViewPager
				.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
					@Override
					public void onPageScrolled(int position,
							float positionOffset, int positionOffsetPixels) {

					}

					@Override
					public void onPageSelected(int position) {
						if (position == 0) { // 判断当切换到第0个页面时把currentPosition设置为images.length,即倒数第二个位置，小圆点位置为length-1
							currentPosition = mImageViewList.size()-2;
							dotPosition = mImageViewList.size()-2 - 1;
						} else if (position == mImageViewList.size()-2 + 1) { // 当切换到最后一个页面时currentPosition设置为第一个位置，小圆点位置为0
							currentPosition = 1;
							dotPosition = 0;
						} else {
							currentPosition = position;
							dotPosition = position - 1;
						}
						// 把之前的小圆点设置背景为暗红，当前小圆点设置为红色
						mImageViewDotList
								.get(prePosition)
								.setBackgroundResource(R.drawable.red_dot_night);
						mImageViewDotList.get(dotPosition)
								.setBackgroundResource(R.drawable.red_dot);
						prePosition = dotPosition;
					}

					@Override
					public void onPageScrollStateChanged(int state) {
						// 当state为SCROLL_STATE_IDLE即没有滑动的状态时切换页面
						if (state == ViewPager.SCROLL_STATE_IDLE) {
							mViewPager.setCurrentItem(currentPosition, false);
						}
					}
				});
	}

	// 设置轮播小圆点
	private void setDot() {
		// 设置LinearLayout的子控件的宽高，这里单位是像素。
		LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(15, 15);
		params.rightMargin = 20;
		// for循环创建images.length个ImageView（小圆点）
		for (int i = 0; i < images.length; i++) {
			ImageView imageViewDot = new ImageView(getActivity());
			imageViewDot.setLayoutParams(params);
			// 设置小圆点的背景为暗红图片
			imageViewDot.setBackgroundResource(R.drawable.red_dot_night);
			mLinearLayoutDot.addView(imageViewDot);
			mImageViewDotList.add(imageViewDot);
		}
		
		// 设置第一个小圆点图片背景为红色
		mImageViewDotList.get(dotPosition).setBackgroundResource(
				R.drawable.red_dot);
	}

	// 设置轮播小圆点
	private void setDotmod() {
		// 设置LinearLayout的子控件的宽高，这里单位是像素。
		LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(15, 15);
		params.rightMargin = 20;
		// for循环创建images.length个ImageView（小圆点）
		for (int i = 0; i < mImageViewList.size()-2; i++) {
			ImageView imageViewDot = new ImageView(getActivity());
			imageViewDot.setLayoutParams(params);
			// 设置小圆点的背景为暗红图片
			imageViewDot.setBackgroundResource(R.drawable.red_dot_night);
			mLinearLayoutDot.addView(imageViewDot);
			mImageViewDotList.add(imageViewDot);
		}
		// 设置第一个小圆点图片背景为红色
		mImageViewDotList.get(dotPosition).setBackgroundResource(
				R.drawable.red_dot);
	}
	
	private void initData() {

		mImageViewList = new ArrayList<ImageView>();
		mImageViewDotList = new ArrayList<ImageView>();
		ImageView imageView = null;

		for (int i = 0; i < images.length + 2; i++) {
			if (i == 0) { // 判断当i=0为该处的ImageView设置最后一张图片作为背景
				imageView = new ImageView(getActivity());
				imageView.setBackgroundResource(images[images.length - 1]);
				mImageViewList.add(imageView);
			} else if (i == images.length + 1) { // 判断当i=images.length+1时为该处的ImageView设置第一张图片作为背景
				imageView = new ImageView(getActivity());
				imageView.setBackgroundResource(images[0]);
				mImageViewList.add(imageView);
			} else { // 其他情况则为ImageView设置images[i-1]的图片作为背景
				imageView = new ImageView(getActivity());
				imageView.setBackgroundResource(images[i - 1]);
				mImageViewList.add(imageView);
			}
		}
	}

	private void initView() {
		tv_gonggao = (LinearLayout) layout.findViewById(R.id.tv_gonggao);
		tv_huodong = (LinearLayout) layout.findViewById(R.id.tv_huodong);
		tv_quanzi = (LinearLayout) layout.findViewById(R.id.tv_quanzi);
		tv_gonggaotitle = (TextView) layout.findViewById(R.id.tv_gonggaotitle);
		tv_huodongtitle = (TextView) layout.findViewById(R.id.tv_huodongtitle);
		tv_quanzititle = (TextView) layout.findViewById(R.id.tv_quanzititle);
		iv_gonggaoimg = (ImageView) layout.findViewById(R.id.iv_gonggaoimg);
		iv_huodongimg = (ImageView) layout.findViewById(R.id.iv_huodongimg);
		iv_quanziimg = (ImageView) layout.findViewById(R.id.iv_quanziimg);

		iv_newgonggao = (ImageView) layout.findViewById(R.id.iv_newgonggao);
		iv_newhuodong = (ImageView) layout.findViewById(R.id.iv_newhuodong);
		iv_newquanzi = (ImageView) layout.findViewById(R.id.iv_newquanzi);

		mViewPager = (ViewPager) layout.findViewById(R.id.vp_main);
		mLinearLayoutDot = (LinearLayout) layout.findViewById(R.id.ll_main_dot);
		// lv_friends = (ListView) layout.findViewById(R.id.lv_friends);
		tv_gonggao.setOnClickListener(this);
		tv_huodong.setOnClickListener(this);
		tv_quanzi.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.tv_gonggao:

			getActivity().runOnUiThread(new Runnable() {

				@Override
				public void run() {
					// TODO Auto-generated method stub
					NoticeInfo_ID = TNoticeInfo_ID;
					iv_newgonggao.setVisibility(iv_newgonggao.GONE);
					iv_gonggaoimg.setVisibility(iv_newgonggao.GONE);
					
					tv_gonggaotitle.setText("我的公告");
					SPUtil.putString(ctx, "NoticeInfo_ID", TNoticeInfo_ID);
				}
			});

			intent = new Intent(getActivity(), GonggaoActivity.class);
			startActivity(intent);
			break;
		case R.id.tv_huodong:

			getActivity().runOnUiThread(new Runnable() {

				@Override
				public void run() {
					// TODO Auto-generated method stub
					MeetingInfo_ID = TMeetingInfo_ID;
					iv_newhuodong.setVisibility(iv_newhuodong.GONE);
					iv_huodongimg.setVisibility(iv_newhuodong.GONE);
					tv_huodongtitle.setText("我的活动");
					SPUtil.putString(ctx, "MeetingInfo_ID", TMeetingInfo_ID);
				}
			});

			intent = new Intent(getActivity(), HuodongActivity.class);
			startActivity(intent);
			break;
		case R.id.tv_quanzi:
			getActivity().runOnUiThread(new Runnable() {

				@Override
				public void run() {
					// TODO Auto-generated method stub
					CircleMessage_ID = TCircleMessage_ID;
					iv_newquanzi.setVisibility(iv_newquanzi.GONE);
					iv_quanziimg.setVisibility(iv_newquanzi.GONE);
					tv_quanzititle.setText("我的圈子");
					SPUtil.putString(ctx, "CircleMessage_ID", TCircleMessage_ID);
				}
			});

			intent = new Intent(getActivity(), MyQuanziActivity.class);
			startActivity(intent);
			break;
		}
	}
}
